# -*- coding: utf-8 -*-

"""
Created on Fri Jun  8 18:43:24 2018

@author: Administrator
"""
#%%

import os
import shutil
from ..distribute.poolmap import PoolMap

#%%

class Nii2niigz(Shell_script):
    #作用原理：
    #参数说明：
    #返回值说明：
    #举例：
    #调用：
    #被调用：
    #bug：
    
    def __init__(self,input_list=[]):
        self.initialize_input_list(input_list)
        self.concat_inputs()
        self.concat_script()
        if os.path.exists(self.out_file_path):
            #if the file is already exist,then there is no neeed to convert or copy the file.s
            self.stdout_err = None
        if self.suffix in self.in_file_path:
            #if the file which the variable 'in_file_path' pointed to is not in nii.gz format,then 
            #it should be converted to nii.gz by the shell command mri_convert
            shutil.copy2(self.in_file_path,self.easy_analysis_path)
            self.stdout_err = None
        else:
            self.excute_shell_script()
    
    def initialize_input_list(self,input_list):
        if len(input_list) != 3:
            raise Exception("incompatible parameter amount ")
        self.in_file_path = input_list[0]
        self.easy_analysis_path = input_list[1]
        
    def concat_inputs(self):
        self.out_file_path = self.easy_analysis_path + self.os_sep + os.path.split(self.in_file_path)[1].split('.')[0] + self.suffix_gz
        
    def concat_script(self):
        ###########################################################################构造命令、即脚本执行。
        #mri_convert -it nii -ot nii  /download/img.nii    /documents/img.nii.gz
        cmd_3 = r' mri_convert -it nii -ot nii' + self.in_file_path + self.space + self.out_file_path
        self.shell_script = cmd_3